﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessPlatform.Core.BusinessObject.Properties;

namespace BusinessPlatform.Core.BusinessObject.BOParser
{
    /// <summary>
    /// 对象解析器
    /// </summary>
    internal class BOParser : IBOParser
    {
        private IBusinessObjectBase _BusinessObjectEntity;
        private IList<IBOChildren> _Children;

        public BOParser(IBusinessObjectBase entity)
        {
            _BusinessObjectEntity = entity;
            Parser();
        }

        /// <summary>
        /// 对象解析
        /// 获取对象中的子对象，把子对象添加到Children中。
        /// </summary>
        public void Parser()
        {
            var iPropertiesManager = (_BusinessObjectEntity as IBusinessObjectProperties).PropertiesManager;
            foreach (var Property in iPropertiesManager)
            {
                IBusinessObjectListBase BOList = Property.Value.PropertyValue as IBusinessObjectListBase;
                if (BOList != null)//判断对象是否是集合对象
                {
                    IBOChildren Child = new BOChildren(BOList);
                    Child.Parent = _BusinessObjectEntity;
                    Children.Add(Child);
                }
            }
        }
        /// <summary>
        /// 子对象
        /// </summary>
        public IList<IBOChildren> Children
        {
            get
            {
                if (_Children == null)
                {
                    _Children = new List<IBOChildren>();
                }
                return _Children;
            }
        }
    }
}
